package org.client.otdr.resolver;

import org.client.otdr.EventTableCreator;
import org.client.otdr.OTDRID;
import org.openems.entity.Entity;
import org.openems.entity.Key;

import framework.AccessorHelper;
import framework.resolver.UnitResolver;

public class MarkerResolver implements UnitResolver {

	private Key key;

	public MarkerResolver(Key key) {
		this.key = key;
	}

	@Override
	public void resolve(Entity oldEntity, Entity newEntity, AccessorHelper helper) {
		OTDRID id = OTDRID.get();
		Double[] data = helper.getTraceValues(id.TRACE);
		Double x = helper.getMarkerX(key);
		Double max = helper.getTraceXmax(id.TRACE);
		int index = (int)(data.length * x / max);
		helper.setMarkerY(key, data[index]);
		
		new EventTableCreator().create(helper);
	}

}
